package com.student.xujiang.mysmalluse.companylogin.retrofit2protogenesis;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.RelativeLayout;

import com.student.xujiang.R;
import com.student.xujiang.mysmalluse.companylogin.model.LoginResponse;
import com.student.xujiang.mysmalluse.companylogin.model.PersonalInfo;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class UserRecyclerViewActivity extends AppCompatActivity {

    @BindView(R.id.user_recyclerview_smalluse)
    RecyclerView userRecyclerviewSmalluse;
    @BindView(R.id.activity_user_recycler_view)
    RelativeLayout activityUserRecyclerView;

    private List<PersonalInfo> list;

    private RecyclerViewAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_recycler_view);
        ButterKnife.bind(this);
        initData();

        //确定你的布局，在这里是线性布局
        userRecyclerviewSmalluse.setLayoutManager(new LinearLayoutManager(this));
        //设置Adapter
        adapter = new RecyclerViewAdapter(UserRecyclerViewActivity.this,list);
        userRecyclerviewSmalluse.setAdapter(adapter);
    }


    private void initData() {
        // 14、注册(注册一次  多次注册会崩溃)
        EventBus.getDefault().register(UserRecyclerViewActivity.this);

    }


    //  13 、接收粘性事件
    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void StickyEventBus(MessageEvent event) {
        //tvEventbusSendResul.setText(event.msg);
        Log.i("TAG__TETS", "执行测试");
        //显示接收的消息
        LoginResponse loginResponse = event.loginResponse;

       list = loginResponse.getPersonalInfos();

        Log.i("TAG__list", list.toString());

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 15、解注册
        EventBus.getDefault().removeAllStickyEvents();
        EventBus.getDefault().unregister(UserRecyclerViewActivity.this);
    }
}
